package com.weibo.zhuanfa.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.weibo.common.BaseSeverlet;
import com.weibo.zhuanfa.ZhuanFa;
import com.weibo.zhuanfa.service.ZhuanfaService;
import com.weibo.zhuanfa.service.imp.ZhuanfaServiceImp;

public class ZhuanFaSaveServlet extends BaseSeverlet {
	private static Logger logger = Logger.getLogger(ZhuanFaSaveServlet.class);

	@Override
	public void doService(HttpServletRequest request,
			HttpServletResponse response) {
		
		logger.info("直发ZhuanFaSaveServlet被请求了！");
		
		HttpSession session = request.getSession();
		ZhuanFa zhuanfa = (ZhuanFa) session.getAttribute("zhuanfa");
		zhuanfa.setTas_state("草稿");
		ZhuanfaService zhuanfaservice = new ZhuanfaServiceImp();
		if (zhuanfaservice.addZhuanfa(zhuanfa)) {
			try {
				request.getRequestDispatcher("/Task_add_fordard_confirm.jsp")
						.forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			try {
				request.getRequestDispatcher("/Task_add_straight.jsp").forward(
						request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

}
